package org.fhm.zdte.common.protocol;

import org.fhm.zdte.common.constant.protocol.PacketType;
import org.fhm.zdte.common.constant.protocol.ResponseMessageType;
import org.fhm.zdte.common.pojo.Address;
import org.fhm.zdte.common.standard.ISubCmd;

/**
 * The abstract layer for packaged suitable Packet-Message.
 *
 * @author 谭波
 * @since 2023/11/4
 */
public abstract class AbstractMessageWrappers {

    /**
     * Obtain Packet-Message.
     *
     * @param type           Packet-Head: packet type.
     * @param subCmd         Packet-Head: the type of sub instruction.
     * @param identification Packet-Head: the identification of the sender side.
     * @param target         Packet-Head: the identification of the receiver side.
     * @param messageNumber  Packet-Head: the packet message number that is a 32-digit uuid.
     * @param messageLength  Packet-Head: the message length specifies how many packets are split into Packet-Contents.
     * @param fromAddress    Packet-Head: the address of the sender side.
     * @param toAddress      Packet-Head: the address of the receiver side.
     * @param secretKey      Packet-Head: A connection to B requires a secret key that meets the requirements of the B side.
     * @return Packet-Message.
     */
    public abstract AbstractMessageStandard getMessageByPacketType(
            PacketType type, ISubCmd subCmd, String identification,
            String target, String messageNumber,
            Integer messageLength, Address fromAddress, Address toAddress,
            String secretKey
    );

    /**
     * Obtain Ack-Packet-Message.
     *
     * @param type           Packet-Head: packet type.
     * @param subCmd         Packet-Head: the type of sub instruction.
     * @param identification Packet-Head: the identification of the sender side.
     * @param target         Packet-Head: the identification of the receiver side.
     * @param fromAddress    Packet-Head: the address of the sender side.
     * @param toAddress      Packet-Head: the address of the receiver side.
     * @param messageNumber  Packet-Head: the packet message number that is a 32-digit uuid.
     * @return Ack-Packet-Message.
     */
    public abstract AbstractMessageStandard getAckMessageByPacketType(
            PacketType type, ISubCmd subCmd, String identification, String target,
            Address fromAddress, Address toAddress,
            String messageNumber);

    /**
     * Obtain Failed-Ack-Message.
     *
     * @param type                Packet-Head: packet type.
     * @param responseMessageType Packet-Head: Response-Message-Type.
     * @param subCmd              Packet-Head: the type of sub instruction.
     * @param identification      Packet-Head: the identification of the sender side.
     * @param target              Packet-Head: the identification of the receiver side.
     * @param toAddress           Packet-Head: the address of the receiver side.
     * @param messageNumber       Packet-Head: the packet message number that is a 32-digit uuid.
     * @return Failed-Ack-Message.
     */
    public abstract AbstractMessageStandard getFailAckMessageByPacketType(
            PacketType type, ResponseMessageType responseMessageType,
            ISubCmd subCmd, String identification, String target, Address toAddress,
            String messageNumber
    );

    /**
     * Obtain Successful-Ack-Message.
     *
     * @param type           Packet-Head: packet type.
     * @param subCmd         Packet-Head: the type of sub instruction.
     * @param identification Packet-Head: the identification of the sender side.
     * @param messageNumber  Packet-Head: the packet message number that is a 32-digit uuid.
     * @return Successful-Ack-Message.
     */
    public abstract AbstractMessageStandard getSuccessfulAckMessage(
            PacketType type, ISubCmd subCmd, String identification, String messageNumber
    );

    /**
     * Obtain Packet-Message-With-Content.
     *
     * @param type           Packet-Head: packet type.
     * @param subCmd         Packet-Head: the type of sub instruction.
     * @param identification Packet-Head: the identification of the sender side.
     * @param messageNumber  Packet-Head: the packet message number that is a 32-digit uuid.
     * @param messageLength  Packet-Head: the message length specifies how many packets are split into Packet-Contents.
     * @param messageSerial  Packet-Head: the message serial number that is the sequence number of the message after the packet content is split.
     * @param content        Packet-Head: the message content.
     * @return Packet-Message-With-Content.
     */
    public abstract AbstractMessageStandard getMessageWithContent(
            PacketType type,
            ISubCmd subCmd,
            String identification,
            String messageNumber,
            int messageLength,
            int messageSerial,
            byte[] content
    );

    /**
     * Obtain Ack-Packet-Message-With-Content.
     *
     * @param type           Packet-Head: packet type.
     * @param subCmd         Packet-Head: the type of sub instruction.
     * @param identification Packet-Head: the identification of the sender side.
     * @param messageLength  Packet-Head: the message length specifies how many packets are split into Packet-Contents.
     * @param messageSerial  Packet-Head: the message serial number that is the sequence number of the message after the packet content is split
     * @param messageNumber  Packet-Head: the packet message number that is a 32-digit uuid.
     * @param content        Packet-Head: the message content.
     * @return Ack-Packet-Message-With-Content.
     */
    public abstract AbstractMessageStandard getAckMessageWithContent(
            PacketType type,
            ISubCmd subCmd,
            String identification,
            int messageLength,
            int messageSerial,
            String messageNumber,
            byte[] content
    );

    /**
     * Gets the length of the Packet-Message-With-Content.
     *
     * @param identification Packet-Head: the identification of the sender side.
     * @return The length of the package with the message content.
     */
    public abstract int getLengthOfMessageWithContent(String identification);

    /**
     * Gets the length of the Ack-Packet-Message-With-Content.
     *
     * @param identification Packet-Head: the identification of the sender side.
     * @return Ack-Packet-Message-With-Content.
     */
    public abstract int getLengthOfAckMessageWithContent(String identification);

}
